package org.chw.demo.controller

import org.chw.demo.services.DemoService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping(value = "rest")
class DemoController {


    @Autowired
    private DemoService demoService

    @GetMapping(value = "hello/{name}")
    String sayHello(@PathVariable(value = "name") String name) {
        return this.demoService.sayHello(name)
    }

    @GetMapping(value = "data")
    @CrossOrigin
    Map<String,List<List<Object>>> findDataTest() {
        Map<String,List<List<Object>>> date = new HashMap<>()
        List<List<Object>> char1List = new ArrayList<>()
        List<Object> char1ListNode1 = new ArrayList<>()
        char1ListNode1.add("chen")
        char1ListNode1.add("1")

        List<Object> char1ListNode2 = new ArrayList<>()
        char1ListNode2.add("hong")
        char1ListNode2.add("2")

        char1List.add(char1ListNode1)
        char1List.add(char1ListNode2)
        date.put("char1",char1List)

        List<List<Object>> char2List = new ArrayList<>()
        List<Object> char2ListNode1 = new ArrayList<>()
        char2ListNode1.add("a")
        char2ListNode1.add("1")

        List<Object> char2ListNode2 = new ArrayList<>()
        char2ListNode2.add("b")
        char2ListNode2.add("2")

        char2List.add(char2ListNode1)
        char2List.add(char2ListNode2)

        date.put("char2",char2List)

        return date
    }
}
